<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDBPDO";

$sql = "";
try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname",$username,$password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    $sql = "INSERT INTO MyGuests (firstname, lastname, email)
    VALUES ('John', 'Doe', 'john@example.com')";
    $conn->exec($sql);
    echo "数据表 MyGuests 插入记录成功";
} catch (PDOException $e) {
    echo $sql.'<br>'.$e->getMessage();
}